package inc.monsters.mias;

import java.util.Map;

public class LoginBean {
	private String userName;
	private String password;
	private String captcha;
	
	/* This map will be filled by the FacesServlet, via a managed property */
	private Map<String, String> logins;

	public void setLogins(Map<String, String> logins) {
		this.logins = logins;
	}

	public synchronized Map<String, String> getLogins() {
		return logins;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	public String getCaptcha() {
		return captcha;
	}

	public void setCaptcha(String captcha) {
		this.captcha = captcha;
	}

	public String login() {
		if (getUserName() != null 
				&& getLogins().get(getUserName()) != null
				&& getLogins().get(getUserName()).equals(getPassword())) {
			return "login";
		} else {
			return "error";
		}
	}
}
